package com.itheima.controller.admin;

import com.itheima.DTO.SysMenuDTO;
import com.itheima.VO.MenuVO;
import com.itheima.entity.SysMenu;
import com.itheima.result.Result;
import com.itheima.service.SysMenuService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/sys_menu")
@RequiredArgsConstructor
@Slf4j
@RestController
public class SysMenuController {
    private final SysMenuService sysMenuService;

    @GetMapping("/allData")
    public Result<List<MenuVO>> allData(){
        List<MenuVO> sysMenuList = sysMenuService.allData();
        return Result.success(sysMenuList);
    }

    @PostMapping("/add")
    public Result<?> add(@RequestBody SysMenuDTO sysMenuDTO){
        sysMenuService.insertSysMenu(sysMenuDTO);
        return Result.success();
    }

    @GetMapping("/del")
    public Result<?> delete(Integer id){
        sysMenuService.deleteSysMenu(id);
        return Result.success();
    }

    @PostMapping("/update")
    public Result<?> update(@RequestBody SysMenuDTO sysMenuDTO){
        sysMenuService.update(sysMenuDTO);
        return Result.success();
    }

    @GetMapping("/rowInfo")
    public Result<MenuVO> rowInfo(Integer id){
        MenuVO menuVO = sysMenuService.rowInfo(id);
        return Result.success(menuVO);
    }
}
